﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="RssFeed.ascx.cs" company="Tobias Lekman">
//   Licensed under Microsoft Public License (Ms-PL). See lekman.codeplex.com/license for more information.
// </copyright>
// --------------------------------------------------------------------------------------------------------------------

namespace LekmanCom.Controls
{
    using System.Linq;
    using System.Xml.Linq;

    using LekmanCom.Properties;

    /// <summary>
    /// The rss feed.
    /// </summary>
    public partial class RssFeed : FeedUserControl
    {
        #region Constructors and Destructors

        /// <summary>
        /// Initializes a new instance of the <see cref="RssFeed"/> class.
        /// </summary>
        public RssFeed()
            : base(Resources.RssFeedUrl)
        {
        }

        #endregion

        #region Methods

        /// <summary>
        /// Called when the XML data binds.
        /// </summary>
        /// <param name="data">
        /// The XML data.
        /// </param>
        protected override void OnDataBind(XElement data)
        {
            var posts = from post in data.Descendants("item")
                        select new BlogPost(post);

            this.PostsRepeater.DataSource = posts.Take(5);
            this.PostsRepeater.DataBind();
        }

        #endregion
    }
}